//
//  ListViewModel.swift
//  RXmvvmDemo
//
//  Created by jemi on 2019/12/27.
//  Copyright © 2019 jemi. All rights reserved.
//

import RxSwift
import RxCocoa

class ListViewModel{
    
    //表格数据序列
    let tableData: Driver<[String]>
    //停止刷新序列
    let endRefreshing: Driver<Bool>
    
    init(headRefresh: Driver<Void>) {
        
        //网络请求
        let netWorkService = NetWorkService()
        
        //生成查询结果序列
        self.tableData = headRefresh.startWith(()).flatMapLatest{_ in
            netWorkService.getRandomResult()
        }
        
        //生成停止刷新状态序列
        self.endRefreshing = self.tableData.map{_ in true}
    }
    
}
